package com.zzyl.controller.manager;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping(path = "/nursing/plan")
@Api(tags = "护理计划管理")
public class NursingPlanController {
    private final NursingPlanService nursingPlanService;

    /**
     * 条件分页查询
     */
    @GetMapping(path = "/search")
    @ApiOperation("分页查询")
    public ResponseResult<PageResponse<NursingPlanVo>> queryNursingProject(String name,Integer pageNum, Integer pageSize, Integer status){
        PageResponse<NursingPlanVo> nursingPlan=nursingPlanService.queryNursingPlan(name,pageNum,pageSize,status);
        return ResponseResult.success(nursingPlan);
    }

    /**
     * 查询所有护理计划
     */
    @GetMapping
    @ApiOperation("查询所有护理计划")
    public ResponseResult<List<NursingPlanVo>>  findNursingPlanList(){
        List<NursingPlanVo> list=nursingPlanService.findNursingPlanList();
        return ResponseResult.success(list);
    }

    /**
     * 新增护理计划
     */
    @PostMapping
    @ApiOperation("新增护理计划")
    public ResponseResult<Void> addNursingPlan(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.addNursingPlan(nursingPlanDto);
        return ResponseResult.success();
    }

    /**
     * 根据id查询
     */
    @GetMapping(path = "/{id}")
    @ApiOperation("根据id查询（修改前回显）")
    public ResponseResult<NursingPlanVo> findNursingPlanById(@PathVariable("id") Long id){
        NursingPlanVo nursingPlan=nursingPlanService.findNursingPlanById(id);
        return ResponseResult.success(nursingPlan);
    }

    /**
     * 修改护理计划
     */
    @PutMapping()
    @ApiOperation("修改护理计划")
    public ResponseResult<Void> modifyNursingPlan(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.modifyNursingPlan(nursingPlanDto);
        return ResponseResult.success();
    }

    /**
     * 护理计划启用/禁用
     */
    @PutMapping(path = "/{id}/status/{status}")
    @ApiOperation("护理计划启用/禁用")
    public ResponseResult<Void> modifyNursingPlanStatus(@PathVariable("id") Integer id, @PathVariable("status") Integer status){
        nursingPlanService.modifyNursingPlanStatus(id,status);
        return ResponseResult.success();
    }

    /**
     * 删除护理计划
     */
    @DeleteMapping(path = "/{id}")
    @ApiOperation("删除护理计划")
    public ResponseResult<Void> deleteNursingPlan(@PathVariable("id") Integer id){
        nursingPlanService.deleteNursingPlan(id);
        return ResponseResult.success();
    }
}
